<?php

/**
 * mailbox actions.
 *
 * @package    sf_sandbox
 * @subpackage mailbox
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class mailboxActions extends sfActions {
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
       ////Групповое удаление
         public function executeDelbatch(sfWebRequest $request)
      {
          $box = $request->getParameter('del');

          if($request->getParameter('redirect')=='input')
              {
                      foreach($box as $k=>$v)
                      {
                          $d = MailboxPeer::retrieveByPK($v);
                          $d->setDelResiver(true);
                          $d->save();
                      }
                      $this->redirect('mailbox/input');
              }
          if($request->getParameter('redirect')=='output')
              {
                      foreach($box as $k=>$v)
                      {
                          $d = MailboxPeer::retrieveByPK($v);
                          $d->setDelSender(true);
                          $d->save();
                      }
                      $this->redirect('mailbox/output');
              }

          $this->redirect('favorites/input');
       }


	public function executeInput(sfWebRequest $request) {


		if (! $request->getParameter ( 'page' )) {
			$this->page = 1;
		} else {
			$this->page = $request->getParameter ( 'page' );
		}


			$c = new Criteria ( );
			$crit1 = $c->getNewCriterion ( MailboxPeer::TO_ID, $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
			$crit2 = $c->getNewCriterion ( MailboxPeer::DEL_RESIVER, false );
			$crit1->addAnd ( $crit2 );
			$c->add ( $crit1 );
			$c->addAnd ( MailboxPeer::PUB, true );
			$c->addDescendingOrderByColumn ( MailboxPeer::CREATED_AT );
			$this->mail = MailboxPeer::doSelect ( $c );

			$pager = new sfPropelPager ( 'Mailbox', sfConfig::get ( 'app_mailbox_perpage' ) );
			$pager->setCriteria ( $c );
			$pager->setPeerMethod ( 'doSelect' );
			$pager->setPage ( $this->page );
			$pager->init ();
			$this->mail = $pager;

                        ///Выбираем новые сообщения
                        $this->new_messages = MailboxPeer::getNewMessages();
                        ///

		///Кидаем пользователя в layout
	     $this->getRequest()->setAttribute('v', $this->getUser()->getProfile());
		////

	}

	public function executeOutput(sfWebRequest $request) {


		if (! $request->getParameter ( 'page' )) {
			$this->page = 1;
		} else {
			$this->page = $request->getParameter ( 'page' );
		}

		$c = new Criteria ( );
		$crit1 = $c->getNewCriterion ( MailboxPeer::FROM_ID, $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
		$crit2 = $c->getNewCriterion ( MailboxPeer::DEL_SENDER, false );
		$crit1->addAnd ( $crit2 );
		$c->add ( $crit1 );
		$c->addDescendingOrderByColumn ( MailboxPeer::CREATED_AT );
		$this->mail = MailboxPeer::doSelect ( $c );

		$pager = new sfPropelPager ( 'Mailbox', sfConfig::get ( 'app_mailbox_perpage' ) );
		$pager->setCriteria ( $c );
		$pager->setPeerMethod ( 'doSelect' );
		$pager->setPage ( $this->page );
		$pager->init ();
		$this->mail = $pager;

		///Кидаем пользователя в layout
	     $this->getRequest()->setAttribute('v', $this->getUser()->getProfile());
		////
	}

	public function executeDelete(sfWebRequest $request) {


		$m = MailboxPeer::retrieveByPK ( $request->getParameter ( 'id' ) );
		$this->forward404Unless ( $m );
                ////Хозяин
		if ($m->getFromId () == $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' )) {
			$m->setDelSender ( 1 );
			$m->save ();

			$this->redirect ( 'mailbox/output');
		}


		if ($m->getToId () == $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' )) {
			$m->setDelResiver ( 1 );
			$m->save ();
                        $this->redirect ( 'mailbox/input');
		}

                   $this->redirect ( 'mailbox/'.$request->getParameter ( 'redirect' ) );

	}

	public function executeRead(sfWebRequest $request) {

            $this->m = MailboxPeer::retrieveByPK ( $request->getParameter ( 'id' ) );

               ////проверка на деньги
//              if($this->getUser()->getProfile()->getAccount () < sfConfig::get ( 'app_cost_mail_show' ) and sfConfig::get ( 'app_cost_mail_show' )!=0 and $this->getUser()->getProfile()->getGender()=='m')
//                 {
//                   $this->getUser ()->setFlash ( 'error', 'У вас недостаточно средств на счете' );
//                   $this->redirect('@account');
//                 }
//                 elseif(sfConfig::get ( 'app_cost_mail_show' )!=0 and $this->m->getFlRead()!=true and $this->m->getFromId()!=$this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) and $this->getUser()->getProfile()->getGender()=='m')
//                 {
//                    $this->message = __('За просмотр сообщения с вашего счета снято %1% кредитов', array('%1%'=>sfConfig::get('app_cost_mail_show'))) ;
//                    $pf = $this->getUser()->getProfile();
//                    $pf->setAccount($pf->getAccount()- sfConfig::get ( 'app_cost_mail_show' ));
//                    $pf->save();
//
//                    $pa = new Payment ( );
//                    $pa->setUserId ( $this->m->getToId() );
//                    $pa->setPaymentId ( $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
//                    $pa->setLevelId ( 16 );
//                    $pa->setSumma ( sfConfig::get ( 'app_cost_mail_show' ) );
//                    $pa->setDirection ( 0 );
//                    $pa->save ();
//
//
//                 }
		///Ставим флаг о прочтении
		$this->m->setFlRead ( true );
		$this->m->save ();
		////


		$firephp = sfFirePHP::getInstance ( true );
		$firephp->fb ( 'to_id -' . $this->m->getToId () );
		$firephp->fb ( 'from_id -' . $this->m->getFromId () );
		$firephp->fb ( 'user_id -' . $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );

		if ($this->m->getToId () != $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) and $this->m->getFromId () != $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' )) {
			$this->forward ( 'mailbox', 'input' );
		}
		///Кидаем пользователя в layout
	     $this->getRequest()->setAttribute('v', $this->getUser()->getProfile());
		////
	}

	public function executeSend(sfWebRequest $request) {





		$this->form = new frontendMailboxForm ( );
		 $this->getRequest()->setAttribute('v', $this->getUser()->getProfile());
		if ($request->getParameter ( 'id' )) {
			$to_user = sfGuardUserPeer::retrieveByPK ( $request->getParameter ( 'id' ) );
			$this->to_user = $to_user;

			if ($to_user) {
				$this->form->setDefault ( 'to_user', $to_user->getId () );
				////Флаг переписки
				$c = new Criteria ( );
				$c->add ( PerepiskaPeer::TO_ID, $to_user->getId () );
				$c->add ( PerepiskaPeer::FROM_ID, $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
				$cnt = PerepiskaPeer::doCount ( $c );
				if ($cnt > 0) {
					$this->perepiska = true;
				}
			}

		}

		if ($request->isMethod ( 'post' ))

		{
				$to_user = sfGuardUserPeer::retrieveByPk ( $request->getParameter ( 'mailbox[to_user]' ) );

		  ////Проверка на однополость
			  	if($to_user->getGender()==$this->getUser()->getProfile()->getGender())
			  	{
			  	 $this->getUser ()->setFlash ( 'error', __('Вы не можете отправлять сообщения пользователю такого же пола') );
			  	 $this->redirect('profile/show?id='.$to_user->getId());
			  	}
          ////

				$this->to_user = $to_user;
			$this->form->bind ( $request->getParameter ( 'mailbox' ), $request->getFiles ( 'mailbox' ) );
			if ($this->form->isValid ()) {
				$u = $this->getUser ()->getProfile ();


                                 $this->form->getObject()->setFromPartnerId($u->getPartnerId());
                                 $this->form->getObject()->setToPartnerId($to_user->getPartnerId());

				/*
				 * проверяем на первое письмо МУЖИКА
				 */
//				$c = new Criteria ( );
//				$c->add ( MailboxPeer::FROM_ID, $u->getId () );
//				$c->addAnd ( MailboxPeer::TO_ID, $this->to_user->getId() );
//				$cnt = MailboxPeer::doCount ( $c );
//				//die('----'.$cnt);
//				if ($cnt==0) {
//						$this->form->save ();
//						$this->form->getObject ()->setToId ( $to_user->getId () );
//						$this->form->getObject ()->setPub ( true );
//						// потому как бесплатное
//						$this->form->getObject ()->setFree ( true );
//						$this->form->getObject ()->save ();
//					if ( $request->getParameter ( 'personal' )=='true') {
//						$this->redirect ( 'mailbox/personal?id=' . $this->form->getObject ()->getToId () );
//					} else {
//						$this->redirect ( '@mailbox_output' );
//					}
//				}

				if ($u->getAccount () > sfConfig::get ( 'app_cost_mail_send' ) and $u->getGender()=='m') {


						$u->setAccount ( $u->getAccount () - sfConfig::get ( 'app_cost_mail_send' ) );
						$u->save ();

						$pa = new Payment ( );
						$pa->setUserId ( $to_user->getId() );
						$pa->setPaymentId ( $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
						$pa->setLevelId ( 2 );
						$pa->setSumma ( sfConfig::get ( 'app_cost_mail_send' ) );
						$pa->setDirection ( 0 );
						$pa->save ();
						//if(sfConfig::get ( 'app_use_alert_send_mail' )==true)
						///$this->getUser ()->setFlash ( 'message', __('За отправку сообщения с вас снято %1% кредита',array('%1%'=>sfConfig::get ( 'app_cost_mail_send' ))) );



					if ($to_user) {
						$this->form->save ();
						$this->form->getObject ()->setToId ( $to_user->getId () );
						$this->form->getObject ()->setPub ( true );
						$this->form->getObject ()->save ();
					}

					//// Шлем уведомление
					$touser = sfGuardUserPeer::retrieveByPK ( $this->form->getObject ()->getToId () );
					$not = MailnoticePeer::retrieveByPK ( 3 );
					$title = $not->getTitle ();
					$body = $not->parse_body ( array ('%from%' => $u, '%link%' => "<a href='" . sfConfig::get ( 'app_site_url' ). "'>" . __ ( 'ссылку' ) . "</a>" ) );
					myTools::sendMail ( $touser->getEmail (), $title, $body );


					/////
					if ( $request->getParameter ( 'personal' )=='true') {
						$this->redirect ( 'mailbox/personal?id=' . $this->form->getObject ()->getToId () );
					} else {
						$this->redirect ( '@mailbox_output' );
					}
				}
                                elseif($u->getGender()=='w' or sfConfig::get ( 'app_cost_mail_send' )==0)
                                    {
						$this->form->save ();
						$this->form->getObject ()->setToId ( $to_user->getId () );
						$this->form->getObject ()->setPub ( true );
						$this->form->getObject ()->save ();
					//// Шлем уведомление
					$touser = sfGuardUserPeer::retrieveByPK ( $this->form->getObject ()->getToId () );
					$not = MailnoticePeer::retrieveByPK ( 3 );
					$title = $not->getTitle ();
					$body = $not->parse_body ( array ('%from%' => $u, '%link%' => "<a href='" . sfConfig::get ( 'app_site_url' ). "'>" . __ ( 'ссылку' ) . "</a>" ) );
					myTools::sendMail ( $touser->getEmail (), $title, $body );
					if ( $request->getParameter ( 'personal' )=='true') {
						$this->redirect ( 'mailbox/personal?id=' . $this->form->getObject ()->getToId () );
					} else {
						$this->redirect ( '@mailbox_output' );
					}

                                    }
                                else {

					$this->getUser ()->setFlash ( 'error', 'У вас недостаточно средств на счете' );

							return sfView::SUCCESS;

				}

			}

		}

		///Кидаем пользователя в layout
	     $this->getRequest()->setAttribute('v', $this->getUser()->getProfile());
		////
	}

	public function executeAdd_perepiska(sfWebRequest $request) {

		$c = new Criteria ( );
		$c->add ( PerepiskaPeer::FROM_ID, $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
		$c->add ( PerepiskaPeer::TO_ID, $request->getParameter ( 'id' ) );
		$cnt = PerepiskaPeer::doCount ( $c );
		if ($cnt == 0) {
			$u = $this->getUser ()->getProfile ();
			if ($u->getAccount () < sfConfig::get ( 'app_cost_perepiska' )) {
				$this->getUser ()->setFlash ( 'error', 'У вас недостаточно средств на счете' );
				$this->redirect ( '@mailbox_send?id=' . $request->getParameter ( 'id' ) );
			} else {
				$p = new Perepiska ( );
				$p->setFromId ( $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
				$p->setToId ( $request->getParameter ( 'id' ) );
				$p->save ();

				$u->setAccount ( $u->getAccount () - sfConfig::get ( 'app_cost_perepiska' ) );
				$u->save ();

				$pa = new Payment ( );
				$pa->setUserId ( $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
				$pa->setPaymentId ( $this->getUser ()->getAttribute ( 'user_id', null, 'sfGuardSecurityUser' ) );
				$pa->setLevelId ( 8 );
				$pa->setSumma ( sfConfig::get ( 'app_cost_perepiska' ) );
				$pa->setDirection ( 0 );
				$pa->save ();

			}
			$user = sfGuardUserPeer::retrieveByPK ( $request->getParameter ( 'id' ) );
			$this->getUser ()->setFlash ( 'message', __('Вы открыли переписку все дальнейшие сообщения будут бесплатны') );
		} else {
			$this->getUser ()->setFlash ( 'message', __('Вы уже открыли переписку с этим пользователем') );
		}

		if (sfConfig::get ( 'app_mail_personal' ) == true) {
			$this->redirect ( 'mailbox/personal?id=' . $request->getParameter ( 'id' ) );
		} else {
			$this->redirect ( '@mailbox_send?id=' . $request->getParameter ( 'id' ) );
		}
	}

	public function executePersonal(sfWebRequest $request) {
		$this->form = new MailboxForm ( );
		$this->to_user = sfGuardUserPeer::retrieveByPK ( $request->getParameter ( 'id' ) );
		$this->forward404Unless ( $this->to_user );
		$to_user = sfGuardUserPeer::retrieveByPK ( $request->getParameter ( 'id' ) );
		$this->form->setDefault ( 'to_user', $to_user->getId () );
		$this->form->setDefault ( 'from_id', $this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ) );

		//// Передаем переписку если есть
		if(sfConfig::get('app_use_perepiska')==true)
		{
			$c = new Criteria();
			$c->add(PerepiskaPeer::FROM_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
			$c->addAnd(PerepiskaPeer::TO_ID, $request->getParameter ( 'id' ));
			$cp = PerepiskaPeer::doCount($c);
			if($cp>0)
			{
			$this->perepiska = true;
			}
		}
		///

		/// проверяем нет ли в фаворитах, если нет добавляем
		 $cf = new Criteria();
		 $cf->add(FavoritePeer::USER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
		 $cf->add(FavoritePeer::FAV_ID,$this->to_user->getId());
		 $cnt = FavoritePeer::doCount($cf);
		 if($cnt==0)
		 {
		 	$f = new Favorite();
		 	$f->setUserId($this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
		 	$f->setFavId($this->to_user->getId());
		 	$f->save();
		 	$this->getUser ()->setFlash ( 'message', __('Пользователь был добавлен в друзья') );
		 }
		///

		$c = new Criteria ( );
		$crit1=$c->getNewCriterion(MailboxPeer::FROM_ID,$this->to_user->getId ());
		$crit2=$c->getNewCriterion(MailboxPeer::TO_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
		$crit22=$c->getNewCriterion(MailboxPeer::DEL_RESIVER,false);
		$crit1->addAnd($crit2);
		$crit1->addAnd($crit22);
		$c->add($crit1);

   		$crit3=$c->getNewCriterion(MailboxPeer::FROM_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
		$crit4=$c->getNewCriterion(MailboxPeer::TO_ID,$this->to_user->getId ());
		$crit33=$c->getNewCriterion(MailboxPeer::DEL_SENDER,false);
		$crit3->addAnd($crit4);
		$crit3->addAnd($crit33);
		$c->addOr($crit3);



		$c->addDescendingOrderByColumn ( MailboxPeer::ID );

		if (! $request->getParameter ( 'page' )) {
			$this->page = 1;
		} else {
			$this->page = $request->getParameter ( 'page' );
		}

		$pager = new sfPropelPager ( 'Mailbox', sfConfig::get ( 'app_mailbox_perpage' ) );
		$pager->setCriteria ( $c );
		$pager->setPeerMethod ( 'doSelect' );
		$pager->setPage ( $this->page );
		$pager->init ();
		$this->mail = $pager;

		$this->setLayout ( 'personal_mail_layout' );
		sfConfig::set ( 'sf_web_debug', false );

		 //Кидаем пользователя в layout
	     $this->getRequest()->setAttribute('v', $this->getUser()->getProfile());
		////
	}



  public function executeAddblack(sfWebRequest $request)
  {
    $user = sfGuardUserPeer::retrieveByPK($this->getRequestParameter('id'));
    $this->forward404Unless($user );
    $c = new Criteria();
    $c->add(BlacklistPeer::USER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
    $c->add(BlacklistPeer::BLACK_ID,$this->getRequestParameter('id'));
    $cnt = BlacklistPeer::doCount($c);
    if($cnt==0)
    {
    $b = new Blacklist();
    $b->setUserId($this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
    $b->setBlackId($this->getRequestParameter('id'));
    $b->save();

    }
    $this->redirect('@mailbox_input?filter=black');
  }

  public function executeAddfav(sfWebRequest $request)
  {
    if($request->getParameter('id'));
    $user = sfGuardUserPeer::retrieveByPK($request->getParameter('id'));
    $this->forward404Unless($user);

    $c = new  Criteria();
    $c->add(FavoritePeer::FAV_ID,$request->getParameter('id'));
    $c->addAnd(FavoritePeer::USER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
    $f = FavoritePeer::doCount($c);
    if($f==0)
    {

    	$fav = new Favorite();
    	$fav->setUserId($this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
    	$fav->setFavId($request->getParameter('id'));
    	$fav->save();
    }

    $this->redirect('@mailbox_input?filter=fav');
  }

  public function executeDelfav(sfWebRequest $request)
  {
  	$c = new Criteria();
  	$c->add(FavoritePeer::FAV_ID,$request->getParameter('id'));
  	$c->add(FavoritePeer::USER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
    $fav = FavoritePeer::doSelectOne($c);
    $this->forward404Unless($fav);
    if($fav->getUserId()==$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ))
    $fav->delete();
    $this->redirect('@mailbox_input?filter=fav');

  }


  public function executeDelblack(sfWebRequest $request)
  {
  	$c = new Criteria();
  	$c->add(BlacklistPeer::USER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
  	$c->add(BlacklistPeer::BLACK_ID,$this->getRequestParameter('id'));
    $bl = BlacklistPeer::doSelectOne($c);
    $this->forward404Unless($bl );
    $bl->delete();
    $this->redirect('@mailbox_input?filter=black');
  }

  public function executeTranslate(sfWebRequest $request)
  {
    if($request->getParameter('in_tiny')=='true')
    {
    	$this->in_tiny = true;
    }
    else
    {
    	$this->in_tiny = false;
    }

  	//$string = preg_replace('/<img.*\/>/','',$request->getParameter('trsl'));

  	$string = strip_tags($request->getParameter('trsl'));
  	$lang = $this->get_lang($string);
  	   //   $lang = get_lang($string);
      if ($lang=="en") list($l1,$l2)=array("en","ru");
      if ($lang=="ru") list($l1,$l2)=array("ru","en");

      $curl = curl_init();
      curl_setopt($curl, CURLOPT_HEADER, 0);
      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
      curl_setopt($curl, CURLOPT_URL, "http://translate.google.com/translate_t?sl=".$l1."&tl=".$l2."");
      curl_setopt($curl, CURLOPT_POSTFIELDS, "hl=ru&ie=UTF-8&text=".urlencode(trim($string))."");
      $res = curl_exec($curl);

      //echo $res;
      //die;
      curl_close ($curl);


      /*
      $res = str_replace(array("\r","\n"),"",$res);
      $res = preg_replace("/ +/"," ",$res);
      $res = $this->format_HTML($res);


      preg_match("|id=\"result_box\" dir=\"ltr\">(.*)</div>|Uis", $res, $arr);
      print_r($arr);
	  */

      //$res = 'asasaa<div id="result_box" dir="ltr">Hi</div><div id="clir">';

    //  $f = fopen('c:/1.txt','r+');
     // fputs($f,$res,1000000);
     // fclose($f);

      preg_match("|<div id=result_box dir=\"ltr\">(.*)</div>|Uis", $res, $arr);
      //echo iconv("windows-1251","utf-8",$res);
      //print_r($arr);


     // echo '--'.$arr[1];
     //die;
     if($lang=='en')
     {
      $this->message = iconv("KOI8-R","utf-8",$arr[1]);
     }
     else
     {
     	$this->message = $arr[1];
     }


  }


public function format_HTML($html) {
    //$html = @iconv("windows-1251","utf-8",$html);
    $config = array(
          "doctype" => "auto",
          "drop-empty-paras" => true,
          "show-body-only" => true,
          "char-encoding" => "utf8",
          "hide-comments" => true,
          "wrap" => 2048,
          "quote-marks" => true
    );
    $tidy = tidy_parse_string($html,$config,"UTF8");
    $body = tidy_get_body($tidy);
    tidy_clean_repair($tidy);
    //$html = @iconv("utf-8","windows-1251",$body->value);
    $html = str_replace(array("<body>","</body>","<form>","</form>","\&quot;"),"",$html);

    $html = str_replace("=\r\n\"","=\"",$html);


    return $html;
}


public function get_lang($string) {
    $true = array();
    $ru   = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я');
    foreach ($ru as $ln) {
        if (is_numeric(strpos($string,$ln)))
            $true[]=1;
    }
    if (sizeof($true)>0 && in_array("1",$true))
        return "ru";
    else
        return "en";
}



}
?>